<template>
  <div>
    <div class="pay_box">
      <el-form>
        <el-form-item label="收费日期">
          <el-date-picker
            v-model="form.orderTimeStart"
            class="pay_date"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="开始时间"
          ></el-date-picker
          >----
          <el-date-picker
            style="marigin-left:4%;"
            v-model="form.orderTimeEnd"
            class="pay_date"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="结束时间"
          ></el-date-picker>
          <el-input
            class="pay_date"
            v-model="form.patientName"
            placeholder="患者姓名"
          ></el-input>
          <el-input
            class="pay_date"
            v-model="form.memberName"
            placeholder="收费人员"
          ></el-input>
          <el-radio v-model="form.type" :label="1">按收费方式</el-radio>
          <el-radio v-model="form.type" :label="2">按收费分类</el-radio>
          <el-button
            type="primary"
            circle
            icon="el-icon-search"
            @click="getChartTable(-1)"
          ></el-button>
          <el-button type="primary" style="float:right;" @click="exportExcel()"
            >导出</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="pay_box">
      <table v-if="!showDay" class="table-box">
        <thead>
          <tr>
            <th style="text-align:center;font-size:18px;" colspan="21">
              收费日报报表
            </th>
          </tr>
          <tr>
            <th>姓名</th>
            <th>门诊号</th>
            <th>费用统计</th>
            <th>折后金额</th>
            <th>现金</th>
            <th>微信</th>
            <th>支付宝</th>
            <!-- <th>POS机信用卡</th> -->
            <!-- <th>积分抵扣</th> -->
            <th>余额支付</th>
            <!-- <th>医保支付</th> -->
            <!-- <th>商保支付</th> -->
            <th>挂账</th>
            <th>卡券</th>
            <th>减免</th>
            <th>实收合计</th>
            <th style="width:200px;">备注</th>
            <th>日期</th>
            <th>收费人员</th>
            <th>接诊人员</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item, index) in tabList" :key="index">
            <td>{{ item.payWay.patientName }}</td>
            <td>{{ item.payWay.cureCode }}</td>
            <td>￥{{ item.payWay.allAmount }}</td>
            <td>￥{{ item.payWay.zheHouAmount }}</td>
            <td>￥{{ item.payWay.xianJin }}</td>
            <td>￥{{ item.payWay.weiXin }}</td>
            <!-- <td>￥{{item.payWay.yinHangKa}}</td> -->
            <td>￥{{ item.payWay.zhiFubao }}</td>
            <!-- <td>￥{{item.payWay.jiFen}}</td> -->
            <td>￥{{ item.payWay.yuE }}</td>
            <!-- <td>￥{{item.payWay.yiBao}}</td> -->
            <!-- <td>￥{{item.payWay.shangBao}}</td> -->
            <td>￥{{ item.payWay.guaZhang }}</td>
            <td>￥{{ item.payWay.kaQuan }}</td>
            <td>￥{{ item.payWay.jianMian }}</td>
            <td>￥{{ item.payWay.shiJiAmount }}</td>
            <td style="width:200px;">{{ item.payWay.desc }}</td>
            <td>{{ item.payWay.date }}</td>
            <td>{{ item.payWay.memberName }}</td>
            <td>{{ item.payWay.doctorName }}</td>
            <td>
              <el-link
                type="success"
                v-if="item.payWay.patientId != undefined"
                @click="getOrderDetail(item, 1)"
                :underline="false"
                >查看详情</el-link
              >
            </td>
          </tr>
          <tr class="foot_tatol">
            <td>合计</td>
            <td></td>
            <td>￥{{ orderDayCount.allAmount }}</td>
            <td>￥{{ orderDayCount.zheHouAmount }}</td>
            <td>￥{{ orderDayCount.xianJin }}</td>
            <!-- <td>￥{{orderDayCount.yinHangKa}}</td> -->
            <td>￥{{ orderDayCount.weiXin }}</td>
            <td>￥{{ orderDayCount.zhiFubao }}</td>
            <!-- <td>￥{{orderDayCount.jiFen}}</td> -->
            <td>￥{{ orderDayCount.yuE }}</td>
            <!-- <td>￥{{orderDayCount.yiBao}}</td> -->
            <!-- <td>￥{{orderDayCount.shangBao}}</td> -->
            <td>￥{{ orderDayCount.guaZhang }}</td>
            <td>￥{{ orderDayCount.kaQuan }}</td>
            <td>￥{{ orderDayCount.jianMian }}</td>
            <td>￥{{ orderDayCount.shiJiAmount }}</td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
          </tr>
        </tbody>
      </table>
      <table v-if="showDay" class="table-box">
        <thead>
          <tr>
            <th style="text-align:center;font-size:18px;" colspan="21">
              收费日报报表
            </th>
          </tr>
          <tr>
            <th>姓名</th>
            <th>门诊号</th>
            <th>诊疗费</th>
            <th>药费</th>
            <th>实验室检查</th>
            <th>辅助检查</th>
            <th>治疗</th>
            <th>材料</th>
            <th>其他</th>
            <th>合计</th>
            <th>收费时间</th>
            <th>收费人员</th>
            <th>接诊医生</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item, index) in tabList" :key="index">
            <td>{{ item.payType.patientName }}</td>
            <td>{{ item.payType.cureCode }}</td>
            <td>￥{{ item.payType.zhenLiao }}</td>
            <td>￥{{ item.payType.yao }}</td>
            <td>￥{{ item.payType.check }}</td>
            <td>￥{{ item.payType.fuzhu }}</td>
            <td>￥{{ item.payType.zhiliao }}</td>
            <td>￥{{ item.payType.cailiao }}</td>
            <td>￥{{ item.payType.other }}</td>
            <td>￥{{ item.payType.allAmount }}</td>
            <td>{{ item.payType.date }}</td>
            <td>{{ item.payType.memberName }}</td>
            <td>{{ item.payType.doctorName }}</td>
            <td>
              <el-link
                @click="getOrderDetail(item.payType, 2)"
                type="success"
                :underline="false"
                >查看详情</el-link
              >
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <br />
    <pager v-model="pager" @change-pagenum="getChartTable"></pager>
  </div>
</template>
<script>
import Excel from "@/_js/excel.js";
export default {
  data() {
    return {
      form: {
        orderTimeStart: "",
        orderTimeEnd: "",
        patientName: "",
        memberName: "",
        type: 1
      },
      orderDayCount: "",
      showDay: false,
      pager: { pageSize: 10, pageNum: 1, total: 0 },
      tabList: []
    };
  },
  mounted() {
    this.getChartTable();
    this.form.orderTimeStart = this.getDate();
    this.form.orderTimeEnd = this.getNewDate();
  },
  methods: {
    getChartTable() {
      let th = this;
      th.showLoading();
      let j = Object.assign(th.form, th.pager);
      th.$api
        .getOrderDayReportByChart(j)
        .then(res => {
          if (res.executed) {
            th.tabList = res.dataBody.pageInfo.list;
            th.orderDayCount = res.dataBody.orderDayCount.payWay;
            th.pager.total = res.dataBody.pageInfo.total;
            if (th.form.type == 1) {
              th.showDay = false;
            } else {
              th.showDay = true;
            }
            th.showLoading(false);
          } else {
            th.$message.error(res.message);
            th.showLoading(false);
          }
        })
        .catch(error => {
          th.showLoading(false);
        });
    },
    getOrderDetail(obj, type) {
      //获取详情
      let th = this;
      let j = {};
      if (obj != null) {
        if (type == 1) {
          j = {
            id: th.jiaMi(obj.payWay.cureId),
            total: obj.payWay.totalMoney,
            type: 1,
            orderId: obj.payWay.orderId,
            orderCode: obj.payWay.orderCode,
            patientId: th.jiaMi(obj.payWay.patientId)
          };
        } else {
          j = {
            id: th.jiaMi(obj.cureId),
            total: obj.allAmount,
            type: 1,
            orderId: obj.orderId,
            orderCode: obj.cureCode,
            patientId: th.jiaMi(obj.patientId)
          };
        }
      } else {
        j = {
          id: th.jiaMi(0)
        };
      }
      let urlJson = th.$utils.JsonToUrl(j);
      th.addNavMenu(
        "收费详情",
        "/page/chargeParticulars?" + urlJson,
        "chargeParticulars"
      );
      th.$router.push({
        path: "/page/chargeParticulars",
        query: th.getUrlToken(j)
      });
    },
    exportExcel() {
      let th = this;
      //导出
      th.$api
        .getOrderDayReportByChart({
          pageSize: "1000",
          pageNum: "1",
          type: th.form.type
        })
        .then(res => {
          if (res.executed) {
            if (res.dataBody != undefined) {
              let list = [];
              let data = res.dataBody.pageInfo.list;
              for (let i = 0; i < data.length; i++) {
                let arr = {};
                if (th.form.type == 1) {
                  Object.assign(arr, data[i].payWay);
                } else {
                  Object.assign(arr, data[i].payType);
                }
                if (arr.patientName != "") {
                  list.push(arr);
                }
              }
              // th.dataList   = res.dataBody.pageInfo.list;
              if (th.form.type == 1) {
                Excel(
                  list,
                  [
                    { key: "patientName", name: "姓名" },
                    { key: "cureCode", name: "门诊号" },
                    { key: "allAmount", name: "费用统计" },
                    { key: "zheHouAmount", name: "折后金额" },
                    { key: "shiJiAmount", name: "实收合计" },
                    { key: "xianJin", name: "现金" },
                    { key: "yinHangKa", name: "银行卡" },
                    { key: "weiXin", name: "微信" },
                    // { key: "zhiFubao", name: "支付宝" },
                    // { key: "jiFen", name: "积分抵扣" },
                    { key: "yuE", name: "余额支付" },
                    // { key: "yiBao", name: "医保支付" },
                    // { key: "shangBao", name: "商保支付" },
                    { key: "guaZhang", name: "挂账" },
                    { key: "kaQuan", name: "卡券" },
                    { key: "jianMian", name: "减免" },
                    { key: "date", name: "日期" },
                    { key: "memberName", name: "收费人员" },
                    { key: "doctorName", name: "接诊人员" }
                  ],
                  "收费日报"
                );
              } else {
                Excel(
                  list,
                  [
                    { key: "patientName", name: "姓名" },
                    { key: "cureCode", name: "门诊号" },
                    { key: "zhenLiao", name: "诊疗费" },
                    { key: "yao", name: "药费" },
                    { key: "check", name: "实验室检查" },
                    { key: "fuzhu", name: "辅助检查" },
                    { key: "zhiliao", name: "治疗" },
                    { key: "cailiao", name: "材料" },
                    { key: "other", name: "其他" },
                    { key: "allAmount", name: "合计" },
                    { key: "date", name: "日期" },
                    { key: "memberName", name: "收费人员" },
                    { key: "doctorName", name: "接诊医生" }
                  ],
                  "收费方式日报"
                );
              }
            }
          }
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.pay_box {
  margin-top: 10px;
  display: inline-block;
  width: 100%;
  overflow-x: auto;
  .table-box {
    min-width: 600px;
    font-size: 12px;
    .foot_tatol td {
      color: $error-color;
    }
  }
}
.pay_date {
  width: 10% !important;
  margin-right: 1%;
}
</style>
